<style>
    #topic-add {
        padding: 20px 25px 25px 0;
    }

    .layui-form-label {
        width: 140px;
    }

    .layui-input-block {
        margin-left: 170px;
    }

    .layui-layer-page .layui-layer-content {
        overflow: visible !important;
    }
</style>
<div class="layui-fluid" id="subject-add">
    <form class="layui-form" lay-filter="subject-add-form">
        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-md6">
                    <input type="hidden" id="topicName_subject" name="topicName_subject" autocomplete="off" class="layui-input" data-th-value="${topicName}"/>
                    <input type="hidden" id="topicId_subject" name="topicId_subject" autocomplete="off" class="layui-input" data-th-value="${topicId}"/>
                    <input type="hidden" id="planId_subject" name="planId_subject" autocomplete="off" class="layui-input" data-th-value="${planId}"/>
                    <label class="layui-form-label">学科：</label>
                    <div class="layui-input-block">
                        <select id="subjectTypeCode" name="subjectTypeCode" lay-filter="subjectTypeCode" lay-verify="required">
                            <option th:each="item : ${subjectTypes}"
                                    th:value="${item.code}" th:text="${item.name}">
                            </option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-md3">
                    <div style="float: right">
                        <button id="btnSaveSubject" type="button" data-type="auto" class="layui-btn layui-btn-normal">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<script data-th-inline="javascript">
    layui.use(['website', 'form', 'table','validate', 'laydate'], function () {
        var $ = layui.$,
            website = layui.website,
            layer = layui.layer,
            form = layui.form,
                table = layui.table,
            validate = layui.validate;
        form.verify(validate);
        form.render();
        layui.$('#btnSaveSubject').on('click', function () {
            debugger
            var curSubjectType = $('#subjectTypeCode').val();
            var allDatas = table.cache['chooseSubjectTable'];
            if(allDatas && allDatas.length > 0){
                for(i = 0; i < allDatas.length; i++){
                    if(allDatas[i].subjectTypeCode === curSubjectType){
                        website.alert.warn('该学科已存在！');
                        return;
                    }
                }
            }
            var oneData= { };
            oneData['name'] = $('#topicName_subject').val();
            oneData['topicId'] = $('#topicId_subject').val();
            oneData['planId'] = $('#planId_subject').val();
            oneData['subjectTypeCode'] = curSubjectType;
            oneData['num'] = 0;
            oneData['choose'] = true;
            allDatas.push(oneData);
            layer.closeAll();
            table.reload('chooseSubjectTable' ,{data : allDatas});
        });
    });
</script>